#include <packet/IQ.h>



IQ::IQ() :
	type(IQ_TYPE_GET)
{}

void setType(TYPE type) {
	this->type = type;
}


std::string toXML() {
	std::string buf("<iq");
    if (!getPacketID().empty()) {
        buf.append("id=\"").append(getPacketID()).append("\" ");
    }
    
	if (!getTo().empty()) {
        buf.append("to=\"").append(StringUtils::escapeForXML(getTo())).append("\" ");
    }
    if (!getFrom().empty()) {
        buf.append("from=\"").append(StringUtils::escapeForXML(getFrom())).append("\" ");
    }
    
	buf.append("type=\"").append(getType().getValue()).append("\">");
        
	// Add the query section if there is one.
	std::string queryXML = getChildElementXML();
    if (!queryXML.empty()) {
        buf.append(queryXML);
    }
    // Add the error sub-packet, if there is one.
    XMPPError * error = getError();
    if (error != NULL) {
    	buf.append(error->toXML());
    }
    buf.append("</iq>");
    return buf;
}



